package com.syas.dao.daos;

import com.syas.base.dao.daos.ChainEntityDao;
import com.syas.common.exception.EntityOperateException;
import com.syas.common.exception.ValidatException;
import com.syas.dao.interfaces.IFmgerDao;
import com.syas.model.models.Fmger;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("FmgerDao")
public class FmgerDao extends ChainEntityDao<Integer, Fmger> implements IFmgerDao {

    //获取员工信息集合
    public List<Fmger> getFmgerList(String hql) {
        return (List<Fmger>)this.getSession().createQuery(hql).list();
    }
    //删除员工信息
    public void delete() throws EntityOperateException, ValidatException {
        String sql = " delete from Fmger ";
        this.getSession().createQuery(sql).executeUpdate();
    }

    //获取分公司数
    public int getBrachComyNum(){
        String sql="select distinct departmentLevel3 from sy_fmger";
        return this.getSession().createSQLQuery(sql).list().size();
    }

    //获取直接下属
    public List<Fmger> directSubordteOfFmger(Fmger fmger){
        String hql = "select new Fmger(ezboUname,joinDate,leaveDate) from Fmger fmger where fmger.leaderEzboUname=?";
        return (List<Fmger>)this.getSession().createQuery(hql).setParameter(0, fmger.getEzboUname()).list();
    }
}
